package com.itheim.mapper;

import com.itheim.pojo.Emp;
import com.itheim.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface  EmpMapper {
    //------------------------原始分页查询-----------------------------
//    @Select("select count(*) from emp")
//    long count();
//
//    @Select("SELECT e.* ,d.name deptName FROM emp e LEFT JOIN dept d ON e.dept_id = d.id " +
//            "order by e.update_time desc LIMIT #{start}, #{pageSize}")
//    List<Emp> page(Integer start, Integer pageSize);

    //-------------------------pagehelper
//    @Select("select e.*, d.name deptName from emp e left join dept d on e.dept_id = d.id " +
//            "where " +
//            "e.name like concat('%', #{name}, '%') " +
//            "and e.gender = #{gender} " +
//            "and e.entry_date between #{begin} and #{end} " +
//            "order by e.update_time desc")
    List<Emp> page(EmpQueryParam empQueryParam);

    /**
     * 新增员工数据
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);


    void delete(Integer[] ids);

    Emp getinfo(Integer id);

    void updatebyId(Emp emp);

    @MapKey("pos")
    List<Map<String, Object>> getJobData();

    @MapKey("gender")
    List<Map<String, Object>> getGenderData();

    List<Emp> list();


    Emp selectByUsernameAndPassword(Emp emp);
}
